package com.order.config;

import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @version 1.0
 * @author: yu.tan
 * @date: 2020/11/7 22:28
 * @Description:
 */
//@Component
public class RequestOriginParserDefinition implements RequestOriginParser {

    /**
     * 定义区分来源：本质-通过request域获取来源标识
     * app pc
     * 然后交给流控应用 位置进行匹配
     *
     * @param httpServletRequest
     * @return
     */
    @Override
    public String parseOrigin(HttpServletRequest httpServletRequest) {

        String serviceName = httpServletRequest.getParameter("serviceName");
        if (StringUtils.isEmpty(serviceName)) {
            throw new RuntimeException("serviceName is Empty!");
        }
        return serviceName;
    }
}
